#include <iostream>
#include <pthread.h>
#include <unistd.h>

// 假设VS_CODE_SUCCEED是一些预定义的成功代码
#define VS_CODE_SUCCEED 0

class CFullScanTask {
public:
    int Start();
    bool m_bFinished;

private:
    static void* FileScanThread(void* arg);
    static void* VirusScanThread(void* arg);

    int CreateFileScanThread();
    int CreateVirusScanThread();
};

int CFullScanTask::Start()
{
    int iRet = CreateFileScanThread();
    if ( iRet != VS_CODE_SUCCEED )
    {
        return iRet;
    }
    m_bFinished = false;
    iRet = CreateVirusScanThread();
    if ( iRet != VS_CODE_SUCCEED )
    {
        return iRet;
    }
    return VS_CODE_SUCCEED;
}

void* CFullScanTask::FileScanThread(void* arg)
{
    while (true) {
        std::cout << "File scanning..." << std::endl;
        sleep(1); // 模拟工作
    }
    return NULL;
}

void* CFullScanTask::VirusScanThread(void* arg)
{
    while (true) {
        std::cout << "Virus scanning..." << std::endl;
        sleep(1); // 模拟工作
    }
    return NULL;
}

int CFullScanTask::CreateFileScanThread()
{
    pthread_t thread;
    if (pthread_create(&thread, NULL, FileScanThread, NULL)) {
        std::cerr << "Error creating FileScanThread" << std::endl;
        return 1;
    }
    return VS_CODE_SUCCEED;
}

int CFullScanTask::CreateVirusScanThread()
{
    pthread_t thread;
    if (pthread_create(&thread, NULL, VirusScanThread, NULL)) {
        std::cerr << "Error creating VirusScanThread" << std::endl;
        return 1;
    }
    return VS_CODE_SUCCEED;
}

void test()
{
    CFullScanTask a;
    a.Start();
}

int main()
{
    test();
   	std::cerr << "111111111111111111" << std::endl;
	sleep(5); // 主线程睡眠，观察子线程的输出
	std::cerr << "222222222222222" << std::endl;
    return 0;
}
